import {
  DREAM_EBAG_LOGIN,
  ACCOUNT_CENTER_SYSTEM,
  ACCOUNT_CENTER_LOGIN
} from './host.js'

import http from './http.js'

export const login = params =>
  http.post(DREAM_EBAG_LOGIN + '/v2/auth/login', params, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
export const postLogout = params => {
  return http.post(DREAM_EBAG_LOGIN + '/v2/auth/logout', params, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 发送登录验证码
export function sendCode(data) {
  return http.post(`${DREAM_EBAG_LOGIN}/v2/auth/sendPhoneCode`, data, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 验证码登录
export function codeLogin(data) {
  return http.post(`${DREAM_EBAG_LOGIN}/v2/auth/code/login`, data, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 获取教师学校信息，这个是获取班级等信息,这个可能获取不到学校信息的情况
export const getUserInfo = params => {
  return http.get(
    ACCOUNT_CENTER_SYSTEM + '/api/ai/v1/person/teacher/class/details',
    {
      params
    }
  )
}
// 主要是获取老师的学校信息
export const postUserInfo = params => {
  return http.post(ACCOUNT_CENTER_SYSTEM + '/api/v2/person/info', {
    person_id: params.personId,
    user_type: params.userType
  })
}

export const postClassroomTree = params => {
  return http.post(
    ACCOUNT_CENTER_SYSTEM + '/api/ai/v1/school/class/teacher/teaching',
    params
  )
}

export function getTeachingInfo(teacher_id, roleCode = '') {
  return http.get(
    `${ACCOUNT_CENTER_SYSTEM}/api/ai/v1/person/teacher/class/details/tree`,
    {
      params: {
        teacher_id,
        role_code: roleCode
      }
    }
  )
}

// 获取用户账户信息
export function getAccountInfo(params) {
  return http.post(
    `${ACCOUNT_CENTER_SYSTEM}/api/v2/person/account_info`,
    params
  )
}

// 校验旧密码，更新新密码
export function updatePwd(params) {
  return http.post(`${ACCOUNT_CENTER_LOGIN}/v1/account/password/update`, params)
}

// 更新人员手机号及账号——发送验证码
export function sendPhoneCode(params) {
  return http.post(
    `${ACCOUNT_CENTER_LOGIN}/v1/ai/account/update/phone/send`,
    params
  )
}

// 更新人员手机号及账号——校验验证码
export function verifyPhoneCode(params) {
  return http.post(`${ACCOUNT_CENTER_LOGIN}/v1/ai/account/update/phone`, params)
}
